local errored = {}
local function tracebackex()
    local ret = ""
    local level = 3
    ret = ret .. "stack traceback:\n"
    while true do
        --get stack info
        local info = debug.getinfo(level, "Sln")
        if not info then break end
        if info.what == "C" then                -- C function
            ret = ret .. string.format("\t[C]: in function '%s'\n", info.name or "")
        else           -- Lua function
            ret = ret .. string.format("\t%s:%d: in function '%s'\n", info.short_src, info.currentline, info.name or "")
        end
        --get local vars
        local i = 1
        while true do
            local name, value = debug.getlocal(level, i)
            if not name then break end
            if name~='self' and name~='(*temporary)' and name: sub(1,4)~='(for' then
                value =  tostring(value)
                if value:find("\n") then
                    value = value:match("([^\n]+)").." ……"
                end
                ret = ret .. string.format("\t\t%-20s= %s\n", name,value)
            end

            i = i + 1
        end
        level = level + 1
    end
    return ret
end


debug.trace = function (pause)
    print("-----------------------------------------------------------------")
    print(">>>>>>>>>>>>>>>>>>>>>>>>>以下为局部变量跟踪<<<<<<<<<<<<<<<<<<<<<<<<")
    print(tracebackex())
    print("-----------------------------------------------------------------")
    if pause then os.execute("pause") end;
end